﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CheccCoverplateCulvertAssemble.SlabCulvert
{
    public class CreateSlabCulvert
    {
        /// <summary>
        /// 创建斜盖板
        /// </summary>
        /// <param name="smartSolidLength">盖板长</param>
        /// <param name="frontWide">短边宽度</param>
        /// <param name="queenwide">长边宽度</param>
        /// <param name="thickness">厚度</param>
        /// <returns></returns>
        public static Element CreateSlopingCoverPlate(double smartSolidLength, double frontWide,double queenwide, double thickness)
        {
            List<DPoint3d> belowPoints = new()
            {
                new DPoint3d(-smartSolidLength / 2 * UorToMeters, 0, 0),
                new DPoint3d(smartSolidLength / 2 * UorToMeters, 0, 0),
                new DPoint3d(smartSolidLength / 2 * UorToMeters, -queenwide * UorToMeters, 0),
                new DPoint3d(-smartSolidLength / 2 * UorToMeters, -frontWide * UorToMeters, 0),
                new DPoint3d(-smartSolidLength / 2 * UorToMeters, 0, 0)
            };
            ShapeElement sectiongElement = new(Session.Instance.GetActiveDgnModel(), null, belowPoints.ToArray());
            CurveVector secCur = CurvePathQuery.ElementToCurveVector(sectiongElement);
            SolidKernelEntity solidKernel = CreateBodyFromExtrusion(secCur, thickness, DPoint3d.Zero, DVector3d.UnitZ, Session.Instance.GetActiveDgnModel());
            Convert1.BodyToElement(out Element coverPlateElement, solidKernel, null, Session.Instance.GetActiveDgnModel());
            return coverPlateElement;
        }

        /// <summary>
        /// 创建正盖板
        /// </summary>
        /// <param name="lengthOfPanel">板长</param>
        /// <param name="widthOfPanel">板宽</param>
        /// <param name="fulcrumThickness">支点厚度</param>
        /// <param name="MidSpanThickness">跨中厚度</param>
        /// <returns></returns>
        public static Element CreateStraightCoverPlate(double lengthOfPanel,double widthOfPanel,double fulcrumThickness,double MidSpanThickness)
        {
            List<DPoint3d> belowPoints = new()
            {
                new DPoint3d(0, lengthOfPanel/2* UorToMeters, 0),
                new DPoint3d(0, lengthOfPanel/2* UorToMeters, fulcrumThickness* UorToMeters),
                new DPoint3d(0, 0, MidSpanThickness* UorToMeters),
                new DPoint3d(0, -lengthOfPanel/2* UorToMeters, fulcrumThickness* UorToMeters),
                new DPoint3d(0, -lengthOfPanel/2* UorToMeters, 0),
                new DPoint3d(0, lengthOfPanel/2* UorToMeters, 0)
            };
            ShapeElement sectiongElement = new(Session.Instance.GetActiveDgnModel(), null, belowPoints.ToArray());
            CurveVector secCur = CurvePathQuery.ElementToCurveVector(sectiongElement);
            SolidKernelEntity solidKernel = CreateBodyFromExtrusion(secCur, widthOfPanel, DPoint3d.Zero, DVector3d.UnitX, Session.Instance.GetActiveDgnModel());
            Convert1.BodyToElement(out Element coverPlateElement, solidKernel, null, Session.Instance.GetActiveDgnModel());
            return coverPlateElement;
        }

        public static SolidKernelEntity CreateBodyFromExtrusion(CurveVector secCur, double extrusionLength, DPoint3d centroid, DVector3d extrudDir, DgnModel modelRef)
        {
            BentleyStatus status = Bentley.CIMNET.CIMGeometry.Solid.SolidUtil.Create.BodyFromExtrusion(
                out SolidKernelEntity entity, secCur, extrusionLength * modelRef.GetModelInfo().UorPerMaster, modelRef, extrudDir, false, null);
            return entity;
        }
        public static double UorToMeters = Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMaster;
    }
}
